﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Common.Enums.Archives;
using S.EarTag.API.Mediator.MediatorCommand.AppearanceCommand;
using S.EarTag.Read.API.Application.MediatorCommand.AppearanceCommand;
using S.EarTag.Read.API.Application.MediatorCommand.BodyMeasureCommand;

namespace S.EarTag.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AppearanceController : ControllerBase
    {
        private readonly IMediator _mediator;
        public AppearanceController(IMediator mediator)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 根据可视耳号查询——反填品相测定信息
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetAppearanceEarTag(string? EarTag)
        {
            AppearanceEarTagCommand command= new AppearanceEarTagCommand();
            command.EarTag = EarTag;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据id查询品相测量
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetByIdAppearance(int id)
        {
            AppearanceByIdCommand command= new AppearanceByIdCommand();
            command.AppearanceId= id;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 查询显示品相测量+分页
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="EarTag"></param>
        /// <param name="VarietyEnum"></param>
        /// <param name="Sex"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetAppearanceListPage(int pageIndex=1, int pageSize=12,string? EarTag="", int VarietyEnum = 0,int Sex = 0)
        {
            AppearanceListPageCommand command = new AppearanceListPageCommand();    
            command.pageIndex= pageIndex;
            command.pageSize= pageSize;
            command.EarTag= EarTag;
            command.VarietyEnum= VarietyEnum;
            command.Sex= Sex;
            var list=await _mediator.Send(command);
            return Ok(list);
        }
    }
}
